package com.bsfcs.rag.entity;

import com.bsfcs.rag.enums.IsAccountsEnum;
import com.bsfcs.rag.enums.ProjectStage;
import com.bsfcs.rag.enums.TaskPriority;
import com.bsfcs.rag.enums.TaskState;
import jakarta.persistence.*;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity
@Table(name = "xxhpromrwgl")
public class Task {
    private String formatDate(Date date) {
        if (date == null) return null;
        // 根据需要选择合适的日期格式
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(date);
    }

    public Task() {}

    public Task(String id, String parentid, String title, String states, String priority,
                String projectStage, String describe, String isAccounts, String billcode, String charger,
                String charger_dept_name, String charger_org_name, BigDecimal workprocess, BigDecimal estimated_time,
                BigDecimal registration_time, BigDecimal estimated_day, String resource_role_name, BigDecimal resource_avg_cost,
                Date start_time, Date end_time, BigDecimal remaining_time, Date create_time) {
        this.id = id;
        this.parentId = parentid;
        this.title = title;
        this.states = TaskState.fromCode(states).getDisplayName();
        this.priority = TaskPriority.fromCode(priority).getDisplayName();
        this.project_stage = ProjectStage.fromCode(projectStage).getDisplayName();
        this.describe = describe;
        this.isaccounts = IsAccountsEnum.fromCode(Integer.parseInt(isAccounts)).getDisplayName();
        this.billcode = billcode;
        this.charger = charger;
        this.charger_dept_name = charger_dept_name;
        this.charger_org_name = charger_org_name;
        this.workprocess = workprocess;
        this.estimated_time = estimated_time;
        this.registration_time = registration_time;
        this.estimated_day = estimated_day;
        this.resource_role_name = resource_role_name;
        this.resource_avg_cost = resource_avg_cost;
        this.start_time_str = formatDate(start_time);
        this.end_time_str = formatDate(end_time);
        this.remaining_time = remaining_time;
        this.create_time_str = formatDate(create_time);
    }

    @Id
    @Column(name = "id")
    private String id;
    
    @Column(name = "parentid")
    private String parentId; // 关联到项目表的id字段
    
    @Column(name = "title")
    private String title;

    @Column(name = "states")
    private String states;

    @Column(name = "priority")
    private String priority;

    @Column(name = "start_time")
    private Date start_time;

    private String start_time_str;

    @Column(name = "end_time")
    private Date end_time;

    private String end_time_str;

    @Column(name = "project_stage")
    private String project_stage;
    
    @Column(name = "describe")
    private String describe;

    @Column(name = "isaccounts")
    private String isaccounts;

    @Column(name = "billcode")
    private String billcode;

    @Column(name = "charger")
    private String charger;

    @Column(name = "charger_dept_name")
    private String charger_dept_name;

    @Column(name = "charger_org_name")
    private String charger_org_name;
    
    /**
     * 进度
     */
    @Column(name = "workprocess")
    private BigDecimal workprocess;

    /**
     * 当前预估工时
     */
    @Column(name = "estimated_time")
    private BigDecimal estimated_time;

    /**
     * 当前登记工时
     */
    @Column(name = "registration_time")
    private BigDecimal registration_time;

    /**
     * 当前剩余工时
     */
    @Column(name = "remaining_time")
    private BigDecimal remaining_time;
    
    @Column(name = "create_time")
    private Date create_time;

    private String create_time_str;
    
    @Column(name = "resource_role_name")
    private String resource_role_name;

    @Column(name = "resource_avg_cost")
    private BigDecimal resource_avg_cost;

    /**
     * 预估天数
     */
    @Column(name = "estimated_day")
    private BigDecimal estimated_day;

}